package org.putrpctorest.parameter.impl;

import java.util.ArrayList;

import org.springframework.expression.EvaluationContext;

public class Expressions extends ArrayList<Expression>{
	
	private static final long serialVersionUID = 1L;

	private String description;
	
    public Expressions(String description) {
    	this.description = description;
    }
	
	public void eval(EvaluationContext ctx) {
		for(Expression expression:this) {
			expression.eval(ctx);
		}
	}

	public String getDescription() {
		return description;
	}
	
	@Override
	public String toString() {
		StringBuffer tmp = new StringBuffer();
		tmp.append("[");
		tmp.append(description);
		boolean first = true;
		for(Expression expr:this) {
			if (first) {
				first = false;
			}
			else {
				tmp.append(",");
			}
			tmp.append(expr);
		}
		tmp.append("]");
		
		return tmp.toString();
	}

	public void addAllNew(Expressions expressions) {
		for(Expression expression:expressions) {
			if (!contains(expression)) {
				add(expression);
			}
		}
	}
}
